﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ExecutionContract
{
    public class ExecutionMemberAttribute : Attribute
    {
        public string Path { get; set; }

        public bool isStreamed { get; internal set; }

        public ExecutionMemberAttribute()
        {
            this.isStreamed = true;
        }

        /// <summary>
        /// The method that has the attribute [ExecutionMember(string)] has to be unique. In otherwise there will be problems during the code generation.
        /// </summary>
        /// <param name="_path">This is the path that </param>
        /// <param name="_isVSProject">Optional attribute that should be true as long as the project is started as a Visual Studio project.</param>
        public ExecutionMemberAttribute(string _path, bool _isVSProject = true)
        {
            if (_path.Contains(':'))
            {
                this.Path = _path;
            }
            else
            {
                //path is relativ
                if (_isVSProject)
                {
                    string foo = typeof(ExecutionMemberAttribute).Assembly.CodeBase;
                    //substring to cut of the file:///
                    this.Path = foo.Substring(8) + _path;
                }
                else
                {
                    this.Path = System.Environment.CurrentDirectory + _path;
                }
                
            }
            this.isStreamed = false;
        }
    }
}